<template>
  <div>
    <van-nav-bar
      title="搜索如下"
      left-text="返回"
      left-arrow
      @click-left="onClickLeft"
    />
    <div class="content">
      <div v-if="data.length">
      <van-card
        v-for="item in data"
        :key="item.id"
        :num="item.category_id"
        :price="item.price"
        :title="item.title"
        :thumb="item.cover_url"
        @click="$router.push(`detail/${item.id}`)"
      />
    </div>
    <van-empty v-else description="暂无数据" />
    </div>
  </div>
</template>

<script>
import { search } from '@api/home'
export default {
  name: 'searchList',
  data () {
    return {
      data: []
    }
  },
  mounted () {
    this.search()
  },
  methods: {
    onClickLeft () {
      this.$router.go(-1)
    },
    search () {
      search(this.$route.query.key).then((res) => {
        if (res.status === 200) {
          this.data = res.data.goods.data
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
</style>
